﻿---@diagnostic disable: trailing-space
local extension = Package:new("moepack_passer")
extension.extensionName = "moepack"

Fk:loadTranslationTable{
  ["moepack_passer"] = "萌包-旅客",
}

local U = require "packages.utility.utility"

local MoeFunc = require "packages.moepack.moepack_function"

-- nuannuan
local moe__nikki = General:new(extension, "moe__nikki", "moe", 4, 4, General.Female)

local emo__huanzhuang = fk.CreateTriggerSkill{
  name = "emo__huanzhuang",
  events = { fk.GameStart, fk.TurnStart},
  anim_type = "special",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.GameStart then 
      return true -- 加标记
    else
      return target == player and #player:getTableMark("@[:]emo__huanzhuang") > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart then 
      return true
    else
      local success, dat = room:askForUseActiveSkill(player, "emo__huanzhuang_active", "#emo__huanzhuang-choice", true)
      if success and dat then
        self.cost_data = table.simpleClone(dat)
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart then 
      room:setPlayerMark(player, "@[:]emo__huanzhuang", {"HZqingxin","HZtianmei","HZdianya","HZshuaiqi","HZxinggan"}) 
      room:setPlayerMark(player, "emo__huanzhuang_removed", 0)
    else
      local choice = self.cost_data.interaction
      local mark = player:getTableMark("@[:]emo__huanzhuang")
      table.removeOne(mark, choice)
      room:setPlayerMark(player, "@[:]emo__huanzhuang", #mark > 0 and mark or 0)
      local removed = player:getTableMark("emo__huanzhuang_removed")
      table.insert(removed, choice)
      room:setPlayerMark(player, "emo__huanzhuang_removed", removed)
      local tos = table.map(self.cost_data.targets, Util.Id2PlayerMapper)

      if choice == "HZshuaiqi" then -- 帅气
        room:notifySkillInvoked(player, self.name, "offensive")
        player:broadcastSkillInvoke(self.name, math.random(7,8))
        room:delay(1000)
        room:addPlayerMark(player, "HZshuaiqi-turn")
        room:doIndicate(player.id, table.map(room:getOtherPlayers(player), Util.IdMapper))
        for _, p in ipairs(room:getOtherPlayers(player)) do
          room:setPlayerMark(p, "@@HZshuaiqi_target-turn", 1)
        end

      elseif choice == "HZtianmei" then -- 甜美
        room:notifySkillInvoked(player, self.name, "support")
        player:broadcastSkillInvoke(self.name, math.random(3,4))
        room:delay(1000)
        local cards = self.cost_data.cards
        room:moveCardTo(cards, Player.Hand, tos[1], fk.ReasonGive, self.name, nil, true, player.id)
        if player.dead then return end
        local x = player.maxHp - player:getHandcardNum()
        if x > 0 then
          player:drawCards(x, self.name)
        end

      elseif choice == "HZdianya" then -- 典雅
        room:notifySkillInvoked(player, self.name, "drawcard")
        player:broadcastSkillInvoke(self.name, math.random(5,6))
        local cardtype = room:askForChoice(player, {"basic","trick","equip"},self.name)
        room:delay(1000)
        local get = {}
        for _, id in ipairs(table.connect(room.draw_pile, room.discard_pile)) do
          if Fk:getCardById(id):getTypeString() == cardtype then
            if (cardtype ~= "equip" and table.every(get, function(cid) return Fk:getCardById(cid).trueName ~= Fk:getCardById(id).trueName end)) or (cardtype == "equip" and table.every(get, function(cid) return Fk:getCardById(cid).sub_type ~= Fk:getCardById(id).sub_type end)) then
              table.insert(get, id)
            end
          end 
          if #get == 4 then break end
        end
        if #get > 0 then
          room:moveCardTo(get, Player.Hand, player, fk.ReasonJustMove, self.name)
        end
        if player.dead then return end
        room:askForGuanxing(player, room:getNCards(4))

      elseif choice == "HZqingxin" then -- 清新
        room:notifySkillInvoked(player, self.name, "drawcard")
        player:broadcastSkillInvoke(self.name, math.random(1,2))
        for _, p in ipairs(tos) do
          if not p.dead and p:isWounded() then
            room:recover { num = 1, skillName = self.name, who = p, recoverBy = player }
          end
          p:reset()
          local slots = table.simpleClone(p.sealedSlots)
          table.removeOne(slots, "JudgeSlot")
          room:resumePlayerArea(p, slots)
          p:throwAllCards("j")
        end

      elseif choice == "HZxinggan" then -- 性感
        local to = tos[1]
        if to:isKongcheng() then return false end
        room:notifySkillInvoked(player, self.name, "control")
        player:broadcastSkillInvoke(self.name, math.random(9,10))
        to:filterHandcards()
        local cards = to:getCardIds("h")
        local map = {}
        local choices = {}
        for _, id in ipairs(cards) do
          local color = Fk:getCardById(id):getColorString()
          if map[color] == nil then
            map[color] = {}
            table.insert(choices, color)
          end
          table.insert(map[color], id)
        end
        local _, ch = U.askforChooseCardsAndChoice(player, cards, choices, self.name, "#HZxinggan-choice", {}, 0, 0)
        room:moveCardTo(map[ch], Player.Hand, player, fk.ReasonPrey, self.name, nil, false, player.id)
      end
    end
  end,

  on_lose = function (self, player)
    player.room:setPlayerMark(player, "@[:]emo__huanzhuang", 0)
  end,
  on_acquire = function (self, player)
    local UImark = {"HZqingxin","HZtianmei","HZdianya","HZshuaiqi","HZxinggan"}
    for _, name in ipairs(player:getTableMark("emo__huanzhuang_removed")) do
      table.removeOne(UImark, name)
    end
    player.room:setPlayerMark(player, "@[:]emo__huanzhuang", #UImark > 0 and UImark or 0)
  end,
}

local emo__huanzhuang_active = fk.CreateActiveSkill{
  name = "emo__huanzhuang_active",
  can_use = Util.TrueFunc,
  card_filter = function (self, to_select, selected)
    return self.interaction.data == "HZtianmei"
  end,
  prompt = function (self)
    if (self.interaction or {}).data then
      return Fk:translate(":"..self.interaction.data)
    end
    return ""
  end,
  target_filter = function(self, to_select, selected, cards)
    local choice = self.interaction.data
    if choice == "HZxinggan" then
      return #selected < 1 and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
    elseif choice == "HZtianmei" then
      return #selected < 1 and to_select ~= Self.id and #cards > 0
    elseif choice == "HZqingxin" then
      return #selected < 2
    end
    return false
  end,
  interaction = function()
    return UI.ComboBox {  choices = Self:getTableMark("@[:]emo__huanzhuang") }
  end,
  feasible = function (self, selected, selected_cards)
    local choice = self.interaction.data
    if choice == "HZxinggan" then
      return #selected == 1 and #selected_cards == 0
    elseif choice == "HZtianmei" then
      return #selected == 1 and #selected_cards > 0
    elseif choice == "HZqingxin" then
      return #selected > 0 and #selected <= 3 and #selected_cards == 0
    end
    return #selected == 0 and #selected_cards == 0
  end,
}
Fk:addSkill(emo__huanzhuang_active)

local emo__huanzhuang_tm = fk.CreateTargetModSkill{
  name = "#emo__huanzhuang_tm",
  bypass_times = function(self, player, skill, scope, card, to)
    return card and player:getMark("HZshuaiqi-turn") > 0
  end,
  bypass_distances = function(self, player, skill, card, to)
    return card and player:getMark("HZshuaiqi-turn") > 0
  end,
}
emo__huanzhuang:addRelatedSkill(emo__huanzhuang_tm)

local isArmorOrTreasureSkill = function (skill)
  local name = skill.attached_equip
  if name and type(name) == "string" then
    local card = Fk.all_card_types[name]
    if card then
      return (card.sub_type == Card.SubtypeArmor or card.sub_type == Card.SubtypeTreasure) 
    end
  end
  return false
end
local emo__huanzhuang_invalidity = fk.CreateInvaliditySkill {
  name = "#emo__huanzhuang_invalidity",
  invalidity_func = function(self, from, skill)
    return from:getMark("@@HZshuaiqi_target-turn") > 0
    and not skill.name:endsWith("&") and (isArmorOrTreasureSkill(skill) or not skill:isEquipmentSkill(from))
  end
}
emo__huanzhuang:addRelatedSkill(emo__huanzhuang_invalidity)

local emo__huanzhuang_prohibit = fk.CreateProhibitSkill{
  name = "#emo__huanzhuang_prohibit",
  prohibit_response = function(self, player, card)
    return player:getMark("@@HZshuaiqi_target-turn") > 0 and player.hp > 1
  end,
  prohibit_use = function(self, player, card)
    return player:getMark("@@HZshuaiqi_target-turn") > 0 and player.hp > 1
  end,
}
emo__huanzhuang:addRelatedSkill(emo__huanzhuang_prohibit)

moe__nikki:addSkill(emo__huanzhuang)

local emo__lvxing = fk.CreateTriggerSkill{
  name = "emo__lvxing",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.RoundEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player.room:getTag("RoundCount") <= 5
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x = room:getTag("RoundCount")
    if x < 5 then
      player:drawCards(x, self.name)
    else
      room:setPlayerMark(player, "emo__huanzhuang_removed", 0)
      if player:hasSkill("emo__huanzhuang", true) then
        room:setPlayerMark(player, "@[:]emo__huanzhuang", {"HZqingxin","HZtianmei","HZdianya","HZshuaiqi","HZxinggan"})
      end
    end
  end,
}

moe__nikki:addSkill(emo__lvxing)

Fk:loadTranslationTable{
  ["moe__nikki"] = "暖暖",
  ["#moe__nikki"] = "奇迹暖暖",

  ["emo__huanzhuang"] = "换装",
  [":emo__huanzhuang"] = "游戏开始时，你获得5枚不同的“换装”标记。回合开始时，你可以移去1枚标记执行对应效果：<br>"..
  "①清新：令至多两名角色回复一点体力，重置武将牌，恢复装备栏，弃置判定区所有牌。<br>".. -- 发育
  "②甜美：将任意张牌交给一名其他角色，再将手牌摸至体力上限。<br>".. --支援
  "③典雅：获得指定类型的不同牌名(装备牌改为不同副类别)的四张牌，然后卜算4。<br>".. -- 过牌
  "④帅气：本回合使用牌无距离和次数限制，其他角色的技能、防具和宝物失效，且体力值大于1时不能使用或打出牌。<br>".. -- 输出
  "⑤性感：观看一名其他角色的手牌，获得其中一种颜色的所有牌。", -- 控制

  ["HZqingxin"] = "清新",
  [":HZqingxin"] = "令至多两名角色回复一点体力，重置武将牌，恢复装备栏，弃置判定区所有牌",
  ["HZtianmei"] = "甜美",
  [":HZtianmei"] = "将任意张牌交给一名其他角色，再将手牌摸至体力上限",
  ["HZdianya"] = "典雅",
  [":HZdianya"] = "获得指定类型的不同牌名(装备牌改为不同副类别)的四张牌，然后卜算4",
  ["HZshuaiqi"] = "帅气",
  [":HZshuaiqi"] = "本回合使用牌无距离和次数限制，其他角色的技能、防具和宝物失效，且体力值大于1时不能使用或打出牌",
  ["HZxinggan"] = "性感",
  [":HZxinggan"] = "观看一名其他角色的手牌，获得其中一种颜色的所有牌",

  ["@[:]emo__huanzhuang"] = "换装",
  ["emo__huanzhuang_active"] = "换装",
  ["@@HZshuaiqi_target-turn"] = "被帅晕",
  ["#HZxinggan-choice"] = "获得一种颜色的所有牌",
  ["#emo__huanzhuang-choice"] = "换装:移去1枚“换装”标记执行对应效果",

  ["emo__lvxing"] = "旅行",
  [":emo__lvxing"] = "锁定技，每轮结束时，若X小于5，你摸X张牌，若X等于5，你恢复所有“换装”标记（X为当前游戏轮数）。",
  -- 清新
  ["$emo__huanzhuang1"] = "每一片落花，都将去往不同的地方。",
  ["$emo__huanzhuang2"] = "闭上眼睛，忘记一切，才能听见那些最纯粹的声音。",
  -- 甜美
  ["$emo__huanzhuang3"] = "你是你鼓励，让我有勇气迈出第一步。",
  ["$emo__huanzhuang4"] = "有你陪在身边，我就有了继续走下去的勇气。",
  -- 典雅
  ["$emo__huanzhuang5"] = "一元复始，万象更新。",
  ["$emo__huanzhuang6"] = "烽烟四起，凤鸟一鸣可抵千军。",
  -- 帅气
  ["$emo__huanzhuang7"] = "你逃不掉的，乖乖向我臣服吧。",
  ["$emo__huanzhuang8"] = "我立于顶端，我享有一切。",
  -- 性感
  ["$emo__huanzhuang9"] = "高贵的身份，幸福的温情，真实的爱……都将是我的东西。",
  ["$emo__huanzhuang10"] = "所有的人，都会臣服在我的脚下……献出他们的爱！",

  ["$emo__lvxing1"] = "回忆也是拥有力量的。",
  ["$emo__lvxing2"] = "你喜欢旅行吗？我常常能在旅行中找到设计的新灵感。",
}



local moe__miku = General:new(extension, "moe__miku", "moe", 3, 3, General.Female)

local emo__gongzhu = fk.CreateTriggerSkill{
  name = "emo__gongzhu",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove, fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player.room.current.phase == Player.Play and player.room.current ~= player then
      if event == fk.Damaged then
        return target == player
      else
        for _, move in ipairs(data) do
          if move.from == player.id then
            for _, info in ipairs(move.moveInfo) do
              if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) 
              and Fk:getCardById(info.cardId).color == Card.Red then
                return true
              end
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(1, self.name)
    if event == fk.Damaged and data.from and data.from == room.current and not data.from.dead then
      room:addPlayerMark(data.from, MarkEnum.UncompulsoryInvalidity .. "-turn")
      room:setPlayerMark(data.from, "@@emo__gongzhu-turn", 1)
    end
    local phaseEvent = room.logic:getCurrentEvent():findParent(GameEvent.Phase)
    if phaseEvent == nil then return end
    if player.dying then
      room:setPlayerProperty(player, "dying", false)
    end
    phaseEvent:shutdown()
  end,
}
moe__miku:addSkill(emo__gongzhu)

local emo__diantang = fk.CreateTriggerSkill{
  name = "emo__diantang",
  anim_type = "drawcard",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and player.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local all_names = table.filter(U.getAllCardNames("t"), function (name)
      return not Fk:cloneCard(name).is_passive
    end)
    local times = 1 + player:getMark("emo__diantang_times")
    for i = 1, times do
      local names = table.filter(all_names, function(name)
        return not table.contains(player:getTableMark("emo__diantang_used"), name)
      end)
      local use = U.askForUseVirtualCard(room, player, names, nil, self.name, "#emo__diantang-use:::"..i..":"..times, true, true, true, true)
      if not use then break end
      if use.extra_data and use.extra_data.emo__diantangCancel then
        room:setPlayerMark(player, "emo__diantang_used", {})
      else
        room:addTableMark(player, "emo__diantang_used", use.card.name)
        room:addPlayerMark(player, "emo__diantang_times", 1)
      end
    end
  end,

  refresh_events = {fk.CardEffectFinished},
  can_refresh = function (self, event, target, player, data)
    return target == player and table.contains(data.card.skillNames, self.name) and data.isCancellOut
  end,
  on_refresh = function (self, event, target, player, data)
    local useEvent = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
    if useEvent == nil then return end
    local use = useEvent.data[1]
    use.extra_data = use.extra_data or {}
    use.extra_data.emo__diantangCancel = true
  end,
}
moe__miku:addSkill(emo__diantang)

Fk:loadTranslationTable{
  ["moe__miku"] = "初音未来",
  ["#moe__miku"] = "世界第一公主殿下",
  
  ["emo__gongzhu"] = "公主",
  [":emo__gongzhu"] = "每当你于一名其他角色的出牌阶段内失去红色牌或受到伤害后，你可以摸一张牌，然后结束当前所有结算，若为该角色对你造成的伤害，令其本回合非锁定技失效。",
  ["@@emo__gongzhu-turn"] = "非锁失效",

  ["emo__diantang"] = "殿堂",
  [":emo__diantang"] = "准备阶段，你可以视为使用一张普通锦囊牌（每种牌名限一次），若未被抵消，此后可使用张数+1，若被抵消，清空牌名记录。",
  ["#emo__diantang-use"] = "殿堂：你可以视为使用一张普通锦囊牌（第 %arg 次，共 %arg2 次）",
}
--[[
-- 等待重做
local moe__buzhihuo = General:new(extension, "moe__buzhihuo", "moe", 3, 4, General.Female)

local emo__chuwu = fk.CreateTriggerSkill{
  name = "emo__chuwu",
  anim_type = "switch",
  switch_skill_name = "emo__chuwu",
  events = {fk.AfterCardTargetDeclared, fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player and data.card and data.card.trueName == "slash" then
      if event == fk.AfterCardTargetDeclared then
        return player:getSwitchSkillState(self.name) == fk.SwitchYang
      else
        return player:getSwitchSkillState(self.name) == fk.SwitchYin and player.room.logic:damageByCardEffect()
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    if event == fk.AfterCardTargetDeclared then
      local targets = {}
      local tos = player.room:askForChoosePlayers(player, targets, 1, 1, "#emo__chuwu-choose:::"..data.card:toLogString(), self.name, true)
      if #tos > 0 then
        self.cost_data = tos
        return true
      end
    else
      return player.room:askForSkillInvoke(player, self.name, nil, "#emo__chuwu-invoke:"..data.to.id)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardTargetDeclared then
      table.insert(data.tos, self.cost_data)
      room:sendLog{ type = "#AddTargetsBySkill", from = player.id, to = self.cost_data, arg = self.name, arg2 = data.card:toLogString() }
    else
      data.damage = data.damage - 1
      local e = room.logic:getCurrentEvent():findParent(GameEvent.CardEffect)
      if e then
        local use = e.data[1]
        local tos = use.tos and TargetGroup:getRealTargets(use.tos)
        if tos then
          for _, pid in ipairs(tos) do
            if player.dead then break end
            local to = room:getPlayerById(pid)
            if not to:isNude() then
              local cid = room:askForCardChosen(player, to, "he", self.name)
              room:moveCardTo(cid, Player.Hand, player, fk.ReasonPrey, self.name, nil, false, player.id)
            end
          end
        end
      end
    end
  end,
}
moe__buzhihuo:addSkill(emo__chuwu)

local emo__liying = fk.CreateTriggerSkill{
  name = "emo__liying",
  anim_type = "support",
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and not target.dead and target.phase == Player.Play  then
      local card = Fk:cloneCard("slash")
      local slash_skill = card.skill
      local status_skills = Fk:currentRoom().status_skills[TargetModSkill] or Util.DummyTable
      for _, skill in ipairs(status_skills) do
        if skill:bypassTimesCheck(target, slash_skill, Player.HistoryPhase, card, nil) then return true end
      end
      return target:usedCardTimes("slash", Player.HistoryPhase) < slash_skill:getMaxUseTime(target, Player.HistoryPhase, card, nil)
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#emo__liying-invoke:"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:loseHp(player, 1, self.name)
    if not target.dead then
      target:skip(Player.Discard)
      if (not target:isWounded()) or room:askForChoice(target, {"recover","draw2"}, self.name) == "draw2" then
        target:drawCards(2, self.name)
      else
        room:recover({
          who = target,
          num = 1,
          recoverBy = player,
          skillName = self.name
        })
      end
    end
  end
}
moe__buzhihuo:addSkill(emo__liying)

local emo__xinghuo = fk.CreateActiveSkill{
  name = "emo__xinghuo",
  anim_type = "support",
  card_num = 1,
  target_num = 1,
  prompt = "#emo__xinghuo-prompt",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type ~= Card.TypeBasic 
    and not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and #selected_cards == 1 and Fk:currentRoom():getPlayerById(to_select):getMark("@@emo__xinghuo") == 0
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 2
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:throwCard(effect.cards, self.name, player, player)
    local to = room:getPlayerById(effect.tos[1])
    if not to.dead then
      room:setPlayerMark(to, "@@emo__xinghuo", 1)
    end
  end,
}
local emo__xinghuo_delay = fk.CreateTriggerSkill{
  name = "#emo__xinghuo_delay",
  mute = true,
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return player == target and data.card.trueName == "slash" and player:getMark("@@emo__xinghuo") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data.additionalEffect = (data.additionalEffect or 0) + 1
  end,

  refresh_events = {fk.EventPhaseStart},
  can_refresh = function (self, event, target, player, data)
    return player == target and player:getMark("@@emo__xinghuo") > 0 and player.phase == Player.Discard
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@@emo__xinghuo", 0)
  end,
}
emo__xinghuo:addRelatedSkill(emo__xinghuo_delay)
local emo__xinghuo_targetmod = fk.CreateTargetModSkill{
  name = "#emo__xinghuo_targetmod",
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and player:getMark("@@emo__xinghuo") > 0 and scope == Player.HistoryPhase then
      return 1
    end
  end,
}
emo__xinghuo:addRelatedSkill(emo__xinghuo_targetmod)
moe__buzhihuo:addSkill(emo__xinghuo)

local emo__lishang = fk.CreateTriggerSkill{
  name = "emo__lishang",
  frequency = Skill.Wake,
  events = {fk.EnterDying, fk.HpLost},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  can_wake = function(self, event, target, player, data)
    if event == fk.EnterDying then
      return data.damage
    else
      return player.hp == 1
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, -1)
    if not player.dead and player:isWounded() then
      room:recover { num = player.maxHp - player.hp, skillName = self.name, who = player, recoverBy = player }
    end
    if player.dead then return end
    room:handleAddLoseSkills(player, "-emo__xinghuo|emo__jinran")
    if not player.dead and not player:isNude() and event == fk.EnterDying then
      room:askForUseActiveSkill(player, "emo__jinran", "#emo__jinran-prompt", true)
    end
  end,
}
moe__buzhihuo:addSkill(emo__lishang)

local emo__jinran = fk.CreateActiveSkill{
  name = "emo__jinran",
  frequency = Skill.Limited,
  anim_type = "offensive",
  min_card_num = 1,
  min_target_num = 1,
  prompt = "#emo__jinran-prompt",
  card_filter = function(self, to_select, selected)
    return Fk:getCardById(to_select).suit == Card.Heart and not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected < #selected_cards
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:throwCard(effect.cards, self.name, player, player)
    room:sortPlayersByAction(effect.tos)
    for _, pid in ipairs(effect.tos) do
      local p = room:getPlayerById(pid)
      if not p.dead then
        room:damage { from = player, to = p, damage = math.random(math.max(1, math.min(p.hp, #effect.cards))), skillName = self.name, damageType = fk.FireDamage }
      end
    end
  end,
}
moe__buzhihuo:addRelatedSkill(emo__jinran)
--]]

Fk:loadTranslationTable{
  ["moe__buzhihuo"] = "不知火",
  ["#moe__buzhihuo"] = "离",
  
  ["emo__chuwu"] = "初舞",
  [":emo__chuwu"] = "转换技，阳：当你使用【杀】时，你可以增加一个目标；阴：当你使用【杀】对目标角色造成伤害时，你可以令此伤害-1并获得每名目标角色各一张牌。",
  ["#emo__chuwu_delay"] = "初舞",
  ["#emo__chuwu-invoke"] = "初舞:你可以防止对 %src 造成伤害，获得所有目标角色各一张牌",
  ["#emo__chuwu-choose"] = "初舞:你可以为%arg指定一个额外目标",

  ["emo__liying"] = "离影",
  [":emo__liying"] = "一名角色的出牌阶段结束时，若其本阶段使用【杀】次数小于次数上限，你可以失去一点体力，令其跳过弃牌阶段，然后其选择摸两张牌或回复一点体力。",
  ["#emo__liying-invoke"] = "初舞:你可以失去一点体力，令%src跳过弃牌阶段并摸两张牌或回复一点体力",

  ["emo__xinghuo"] = "星火",
  [":emo__xinghuo"] = "出牌阶段限两次，你可以将弃置一张非基本牌，令一名角色进入“星火”状态（使用【杀】额外结算一次且次数上限+1）直到其弃牌阶段开始。",
  ["@@emo__xinghuo"] = "<font color='#ff3300'>星火</font>",
  ["#emo__xinghuo-prompt"] = "星火:弃置一张非基本牌，令一名角色进入“星火”状态(【杀】额外结算一次且次数上限+1)",
  ["#emo__xinghuo_delay"] = "星火",

  ["emo__lishang"] = "离殇",
  [":emo__lishang"] = "觉醒技，当你{①：因伤害进入濒死状态时；②：失去体力后体力值为1}，你扣减一点体力上限并回复所有体力，失去〖星火〗并获得〖烬染〗，若为条件①，你可以发动〖烬染〗（不计入次数）。",

  ["emo__jinran"] = "烬染",
  [":emo__jinran"] = "限定技，出牌阶段，你可以弃置任意张红桃牌，对至多等量名角色依次造成1-X点火焰伤害（X为目标体力值和弃置牌数的较小值）。",
  ["#emo__jinran-prompt"] = "烬染:弃置任意张红桃牌，对至多等量名角色随机造成火焰伤害",

  ["$emo__chuwu1"] = "第一次听我的歌声吗？",
  ["$emo__chuwu2"] = "歌舞之后，有什么留在了你心底吗？",
  ["$emo__liying1"] = "灯火连天！",
  ["$emo__xinghuo1"] = "离别之时，不需要更多言语。",
  ["$emo__jinran1"] = "归来时，通过火红的花道吧。",
  ["$emo__lishang1"] = "于平海跳跃起舞时，请你注视火光连天的盛景。",
  ["$emo__jinran2"] = "归来时，通过火红的花道吧。",
  ["$emo__lishang2"] = "于平海跳跃起舞时，请你注视火光连天的盛景。",
  ["~moe__buzhihuo"] = "噫……",
}


local moe__saiba_momoi = General:new(extension, "moe__saiba_momoi", "moe", 3, 3, General.Female)
moe__saiba_momoi.shield = 1

--- 更新“灵感”标记
local updataLingganMark = function (player)
  player.room:setPlayerMark(player, "@emo__linggan", player:hasSkill("emo__linggan", true) and string.format("%d-%d-%d-%d",
  player:getMark("emo__linggan_times")+1,
  player:getMark("emo__linggan_choice")+1,
  player:getMark("emo__linggan_num")+3,
  player:getMark("emo__linggan_use")+1) or 0)
end

local emo__linggan = fk.CreateActiveSkill{
  name = "emo__linggan",
  anim_type = "drawcard",
  card_num = 0,
  target_num = 0,
  card_filter = Util.FalseFunc,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 1 + player:getMark("emo__linggan_times")
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local choices = room:askForChoices(player, {"basic","trick","equip"},1,1+player:getMark("emo__linggan_choice"),
    self.name,"#emo__linggan-choice",false)
    local cards = room:getNCards(3 + player:getMark("emo__linggan_num"))
    room:moveCards({
      ids = cards,
      toArea = Card.Processing,
      moveReason = fk.ReasonPut,
      skillName = self.name,
      proposer = player.id,
    })
    room:delay(200)
    local get = {}
    for _, id in ipairs(cards) do
      if table.contains(choices, Fk:getCardById(id):getTypeString()) then
        table.insert(get, id)
        room:setCardEmotion(id, "judgegood")
      end
    end
    room:delay(500)
    if #get > 0 then
      room:moveCardTo(get, Player.Hand, player, fk.ReasonPrey, self.name)
    end
    for i = 1, 2 do
      if player.dead or i > player:getMark("emo__linggan_use") + 1 then break end
      cards = table.filter(cards, function(id) return room:getCardArea(id) == Card.Processing end)
      if #cards == 0 then break end
      if not U.askForUseRealCard(room, player, cards, ".", self.name, "#emo__linggan-use:::"..tostring(i)..
      ":"..tostring(player:getMark("emo__linggan_use") + 1), {expand_pile = cards}) then
        break
      end
    end
    cards = table.filter(cards, function(id) return room:getCardArea(id) == Card.Processing end)
    if #cards > 0 then
      local moveInfos = {}
      if not player.dead then
        local result = room:askForGuanxing(player, cards, nil, nil, self.name, true, {"Top", "pile_discard"})
        cards = result.bottom
        if #result.top > 0 then
          table.insert(moveInfos, {
            ids = table.reverse(result.top),
            toArea = Card.DrawPile,
            moveReason = fk.ReasonPut,
            skillName = self.name,
            proposer = player.id,
          })
        end
      end
      if #cards > 0 then
        table.insert(moveInfos, {
          ids = cards,
          toArea = Card.DiscardPile,
          moveReason = fk.ReasonPutIntoDiscardPile,
          skillName = self.name,
          proposer = player.id,
        })
      end
      room:moveCards(table.unpack(moveInfos))
    end
  end,

  on_acquire = function (self, player)
    updataLingganMark(player)
  end,
  on_lose = function (self, player)
    updataLingganMark(player)
  end,
}
moe__saiba_momoi:addSkill(emo__linggan)

local emo__bugan = fk.CreateTriggerSkill{
  name = "emo__bugan",
  frequency = Skill.Compulsory,
  events = {fk.Damaged, fk.CardEffectCancelledOut},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:hasSkill(emo__linggan, true)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local all_choices = {"emo__linggan_times","emo__linggan_num","emo__linggan_choice","emo__linggan_use"}
    local choices = {}
    for i, n in ipairs(all_choices) do
      if player:getMark(n) < (i == 2 and 3 or 1) then
        table.insert(choices, n)
      end
    end
    if #choices > 0 then
      local choice = room:askForChoice(player, choices, self.name, "#emo__bugan-choice", false, all_choices)
      room:addPlayerMark(player, choice)
      updataLingganMark(player)
    end
    if data.card then
      local n = 0.3 + 0.1 * player:usedSkillTimes(self.name, Player.HistoryGame)
      if math.random() < n then
        local ids = room:getCardsFromPileByRule(".|.|.|.|.|"..data.card:getTypeString(), 1, "allPiles")
        if #ids > 0 then
          room:moveCardTo(ids, Player.Hand, player, fk.ReasonPrey, self.name)
        end
      end
    end
  end,
}
moe__saiba_momoi:addSkill(emo__bugan)

Fk:loadTranslationTable{
  ["moe__saiba_momoi"] = "才羽桃井", -- 王小桃
  ["#moe__saiba_momoi"] = "游戏高手",
  
  ["emo__linggan"] = "灵感",
  [":emo__linggan"] = "出牌阶段限1次，你可以声明1种牌的类型，并亮出牌堆顶的3张牌，你获得声明类型的所有牌，然后你可以使用其中其他类型的1张牌，最后将其余牌置于牌堆顶或弃牌堆。",
  ["#emo__linggan-choice"] = "灵感：声明你要获得牌的类型",
  ["#emo__linggan-use"] = "灵感：可以使用其中的牌（第 %arg 张/至多 %arg2 张）",
  ["emo__linggan_times"] = "发动次数",
  ["emo__linggan_num"] = "亮出牌张数",
  ["emo__linggan_choice"] = "获得牌类型数",
  ["emo__linggan_use"] = "可使用牌张数",
  ["@emo__linggan"] = "灵感",

  ["emo__bugan"] = "不甘",
  [":emo__bugan"] = "锁定技，当你受到伤害后，或你的牌被抵消后，你令〖灵感〗中一个数字+1（至多加至原数值的两倍），然后有一定概率（〖不甘〗发动次数越多，此概率越高）获得一张与造成伤害的牌或被抵消的牌类型相同的牌。",
  ["#emo__bugan-choice"] = "灵感：选择令〖灵感〗中一个数字+1",

  ["$emo__linggan1"] = "啊！灵光乍现，想到个不错的剧本！",
  ["$emo__linggan2"] = "游戏～游戏～打游戏呀～想打游戏～",
  ["$emo__bugan1"] = "不甘心……不甘心！",
  ["$emo__bugan2"] = "诶！？呜呜不可饶恕！",
  ["$emo__bugan3"] = "诶！死了！？我不信我不信！",
  ["~moe__saiba_momoi"] = "啊，真是的！根本就是垃圾游戏啊！",
}


local moe__lilith = General:new(extension, "moe__lilith", "moe", 3, 3, General.Female)

local emo__yushen = fk.CreateTriggerSkill{
  name = "emo__yushen",
  anim_type = "defensive",
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
    and data.from and data.from ~= player.id and player.room:getPlayerById(data.from).phase ~= Player.NotActive
    and not table.contains(player:getTableMark("emo__yushen_forbid"), data.from)
  end,
  on_cost = function(self, event, target, player, data)
    self.cost_data = {tos = {data.from}}
    local num = 1
    if table.contains(player:getTableMark("emo__yushen_draw"), data.from) then
      num = 2
    end
    return player.room:askForSkillInvoke(player, self.name, nil, "#emo__yushen-invoke:"..data.from.."::"..num)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = 1
    if table.contains(player:getTableMark("emo__yushen_draw"), data.from) then
      num = 2
    end
    player:drawCards(num, self.name)
    local to = room:getPlayerById(data.from)
    if not to.dead then
      to:drawCards(num, self.name)
      if not player.dead then
        room:setPlayerMark(player, "@@emo__yushen-turn", to.id)
      end
    end
  end,
}

local emo__yushen_delay = fk.CreateTriggerSkill{
  name = "#emo__yushen_delay",
  anim_type = "defensive",
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return target == player and not player.dead and data.from and player:getMark("@@emo__yushen-turn") == data.from.id
  end,
  on_cost = function(self, event, target, player, data)
    self.cost_data = {tos = {data.from.id}}
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@@emo__yushen-turn", 0)
    room:loseHp(data.from, 1, "emo__yushen")
    if not data.from.dead then
      data.from:drawCards(2, "emo__yushen")
    end
    return true
  end,
}

emo__yushen:addRelatedSkill(emo__yushen_delay)
moe__lilith:addSkill(emo__yushen)

local emo__heiwang = fk.CreateTriggerSkill{
  name = "emo__heiwang",
  anim_type = "special",

  refresh_events = {fk.GameStart, fk.EventAcquireSkill, fk.EventLoseSkill, fk.Deathed, fk.AfterPlayerRevived},
  can_refresh = function(self, event, target, player, data)
    if event == fk.GameStart or event == fk.AfterPlayerRevived then
      return player:hasSkill(self, true)
    elseif event == fk.EventAcquireSkill or event == fk.EventLoseSkill then
      return target == player and data == self and
        not table.find(player.room:getOtherPlayers(player), function(p) return p:hasSkill(self, true) end)
    else
      return target == player and player:hasSkill(self, true, true) and
        not table.find(player.room:getOtherPlayers(player), function(p) return p:hasSkill(self, true) end)
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart or event == fk.EventAcquireSkill or event == fk.AfterPlayerRevived then
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if not table.contains(p:getTableMark("emo__heiwang_target"), player.id) then
          room:handleAddLoseSkills(p, "emo__heiwang&", nil, false, true)
        end
      end
    else
      for _, p in ipairs(room:getOtherPlayers(player, true, true)) do
        room:handleAddLoseSkills(p, "-emo__heiwang&", nil, false, true)
      end
    end
  end,
}

local emo__heiwang_active = fk.CreateActiveSkill{
  name = "emo__heiwang&",
  anim_type = "special",
  card_num = 4,
  target_num = 1,
  prompt = "#emo__heiwang-other",
  interaction = function(self)
    return UI.ComboBox { choices = {"#emo__heiwang_damage", "#emo__heiwang_recover"} }
  end,
  can_use = function(self, player)
    return player:getHandcardNum() > 3
  end,
  card_filter = function (self, to_select, selected)
    if #selected < 4 and table.contains(Self.player_cards[Player.Hand], to_select) then
      local c = Fk:getCardById(to_select)
      if c.suit ~= Card.NoSuit and not Self:prohibitDiscard(c) then
        return #selected == 0 or table.every(selected, function (id)
          return Fk:getCardById(id).suit ~= c.suit
        end)
      end
    end
  end,
  target_filter = function (self, to_select, selected, selected_cards)
    if #selected_cards == 4 then
      return to_select ~= Self.id and not table.contains(Self:getTableMark("emo__heiwang_target"), to_select)
      and Fk:currentRoom():getPlayerById(to_select):hasSkill("emo__heiwang")
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    room:addTableMark(player, "emo__heiwang_target", to.id)
    room:throwCard(effect.cards, self.name, player, player)
    if self.interaction.data == "#emo__heiwang_damage" then
      room:damage { from = player, to = to, damage = 1, skillName = self.name }
      room:addTableMark(to, "emo__yushen_forbid", player.id)
    else
      room:recover { num = 1, skillName = self.name, who = to, recoverBy = player }
      room:addTableMark(to, "emo__yushen_draw", player.id)
    end
    if player.dead or not table.find(room.alive_players, function (p)
      return p ~= player and p:hasSkill("emo__heiwang", true) and not table.contains(player:getTableMark("emo__heiwang_target"), p.id)
    end) then
      room:handleAddLoseSkills(player, "-emo__heiwang&", nil, false, true)
    end
  end,
}
Fk:addSkill(emo__heiwang_active)
moe__lilith:addSkill(emo__heiwang)

Fk:loadTranslationTable{
  ["moe__lilith"] = "莉莉斯",
  ["#moe__lilith"] = "妮妮尔女王",
  
  ["emo__yushen"] = "欲神",
  [":emo__yushen"] = "每回合限一次，当你成为其他角色于其回合内使用牌的目标后，你可以与其各摸一张牌，若如此做，本回合下次你受到其造成的伤害时，防止之，令其失去1点体力并摸两张牌。",
  ["#emo__yushen-invoke"] = "欲神：你可以与 %src 各摸 %arg 张牌，且防止本回合你下次受到其造成的伤害",
  ["#emo__yushen_delay"] = "欲神",
  ["@@emo__yushen-turn"] = "欲神",

  ["emo__heiwang"] = "黑王",
  [":emo__heiwang"] = "每名角色限一次，其他角色的出牌阶段，其可以弃置花色不同的四张手牌并选一项：1.对你造成1点伤害，你不可对其发动“欲神”；2.令你回复1点体力，你对其发动“欲神”时双方摸牌数+1。",
  ["emo__heiwang&"] = "黑王",
  ["#emo__heiwang-other"] = "黑王：你可以弃置花色不同的四张手牌，令拥有“黑王”的角色受到伤害或回复体力",
  ["#emo__heiwang_damage"] = "对其造成伤害",
  ["#emo__heiwang_recover"] = "令其回复体力",
  [":emo__heiwang&"] = "每名角色限一次，出牌阶段，你可以选择一名拥有“黑王”的其他角色，弃置花色不同的四张手牌并选一项：1.对其造成1点伤害，其不可对你发动“欲神”；2.令其回复1点体力，其对你发动“欲神”时双方摸牌数+1。",
}


local moe__angela = General:new(extension, "moe__angela", "moe", 3, 3, General.Female)

local emo__zhouhuo = fk.CreateActiveSkill{
  name = "emo__zhouhuo",
  anim_type = "offensive",
  card_num = 0,
  target_num = 1,
  prompt = "#emo__zhouhuo",
  interaction = function(self)
    local choices = {}
    for _, id in ipairs(Self.player_cards[Player.Hand]) do
      local c = Fk:getCardById(id)
      if c.suit ~= Card.NoSuit and not Self:prohibitDiscard(c) then
        if table.insertIfNeed(choices, c:getSuitString(true)) and #choices == 4 then
          break
        end
      end
    end
    return UI.ComboBox { choices = choices }
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and Self.id ~= to_select and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  can_use = function(self, player)
    return player:getMark("@@emo__zhouhuo-phase") == 0 and
    table.find(player.player_cards[Player.Hand], function(id)
      return not player:prohibitDiscard(Fk:getCardById(id)) and Fk:getCardById(id).suit ~= Card.NoSuit
    end)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    local my_cards = table.filter(player.player_cards[Player.Hand], function(id)
      return not player:prohibitDiscard(Fk:getCardById(id)) and Fk:getCardById(id):getSuitString(true) == self.interaction.data
    end)
    local choices = {}
    to:filterHandcards()
    for _, id in ipairs(to.player_cards[Player.Hand]) do
      local c = Fk:getCardById(id)
      if c.suit ~= Card.NoSuit and not to:prohibitDiscard(c) then
        if table.insertIfNeed(choices, c:getSuitString(true)) and #choices == 4 then
          break
        end
      end
    end
    local to_cards = {}
    if #choices > 0 then
      local choice = room:askForChoice(to, choices, self.name, "#emo__zhouhuo-choice")
      to_cards = table.filter(to.player_cards[Player.Hand], function(id)
        return not to:prohibitDiscard(Fk:getCardById(id)) and Fk:getCardById(id):getSuitString(true) == choice
      end)
    else
      room:sendLog{ type = "#CannotDiscard", from = to.id, toast = true }
    end
    local x = math.min(#my_cards, #to_cards)
    -- 同时移动防止插结
    local moves = {}
    table.insert(moves, { from = player.id, toArea = Card.DiscardPile, ids = my_cards, moveReason = fk.ReasonDiscard, skillName = self.name, proposer = player.id })
    if #to_cards > 0 then
      table.insert(moves, { from = to.id, toArea = Card.DiscardPile, ids = to_cards, moveReason = fk.ReasonDiscard, skillName = self.name, proposer = to.id })
    end
    room:moveCards(table.unpack(moves))
    if player.dead or x == 0 then return end
    if #to_cards > #my_cards then
      room:setPlayerMark(player, "@@emo__zhouhuo-phase", 1)
    end
    if to.dead then return end
    local card = Fk:cloneCard((to:isKongcheng() or player:isKongcheng()) and "fire__slash" or "fire_attack")
    card.skillName = self.name
    if not player:prohibitUse(card) and not player:isProhibited(to, card) then
      local use = { from = player.id, tos = {{to.id}}, card = card, additionalEffect = x > 1 and x - 1 , extraUse = true}
      room:useCard(use)
    end
  end,
}
moe__angela:addSkill(emo__zhouhuo)


local emo__zhuoshao = fk.CreateTriggerSkill{
  name = "emo__zhuoshao",
  anim_type = "offensive",
  events = {fk.Damage},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and data.to ~= player and not data.to.dead
    and data.damageType == fk.FireDamage
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if data.to:getMark("@!ignite") == 0 then
      room:addPlayerMark(data.to, "@!ignite", 1)
    else
      player:drawCards(2, self.name)
    end
  end,
}
moe__angela:addSkill(emo__zhuoshao)


local emo__dunshi = fk.CreateTriggerSkill{
  name = "emo__dunshi",
  anim_type = "control",
  events = {fk.GameStart, fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if not  player:hasSkill(self) then return false end
    if event == fk.GameStart then
      return true
    elseif target == player or table.contains(TargetGroup:getRealTargets(data.tos), player.id) then
      local current = player.room.current
      if current and current.phase == Player.Play then
        local mark = U.getPrivateMark(player, "emo__dunshi")
        if #mark > 0 then
          local useEvents = player.room.logic:getEventsOfScope(GameEvent.UseCard, 5, Util.TrueFunc, Player.HistoryPhase)
          for i, e in ipairs(useEvents) do
            if e.data[1] == data and i == mark[1] then
              return true
            end
          end
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player.dead then return end
    if event == fk.CardUseFinished then
      player:drawCards(3, self.name)
      if room.current ~= player then
        room.current:endPlayPhase()
      end
      if player.dead then return end
      room.logic:getCurrentEvent():findParent(GameEvent.Phase):addCleaner(function()
        self:use(fk.GameStart, player, player, {})
      end)
    else
      local all_choices = {}
      for i = 1, 5 do
        table.insert(all_choices, tostring(i))
      end
      local choices = table.simpleClone(all_choices)
      local mark = U.getPrivateMark(player, "emo__dunshi")
      if #mark > 0 then
        table.removeOne(choices, tostring(mark[1]))
      end
      local choice = room:askForChoice(player, choices, self.name, "#emo__dunshi-choice", false, all_choices)
      U.setPrivateMark(player, "emo__dunshi", {tonumber(choice)})
    end
  end,
}
moe__angela:addSkill(emo__dunshi)


Fk:loadTranslationTable{
  ["moe__angela"] = "安琪拉",
  ["#moe__angela"] = "时之奇旅",
  
  ["emo__zhouhuo"] = "咒火",
  [":emo__zhouhuo"] = "出牌阶段，你可以令一名其他角色与你同时选择弃置一种花色的所有手牌，然后视为对其使用一张结算X次的【火攻】（X为你与其以此法弃置牌数的较小值）。若你或其没有手牌，改为使用火【杀】。若其弃置牌多于你，本阶段〖咒火〗失效。",
  ["#emo__zhouhuo"] = "咒火：选择弃置一种花色和一名其他角色，令其也选择弃置一种花色的手牌",
  ["#CannotDiscard"] = "%from 没有可以弃置的牌",
  ["#emo__zhouhuo-choice"] = "咒火：你须选择弃置一种花色的所有手牌",
  ["@@emo__zhouhuo-phase"] = "咒火失效",

  ["emo__zhuoshao"] = "灼烧",
  [":emo__zhuoshao"] = "锁定技，每当你对其他角色造成火焰伤害后，若其没有“点燃”标记，令其获得之；若有，你摸两张牌。"..
  "<br><font color='grey'>#点燃：受到的火焰伤害+1，直到因火焰伤害进入濒死状态。</font>",
  
  ["emo__dunshi"] = "遁时",
  [":emo__dunshi"] = "游戏开始时，你秘密选择1~5的数字。每个出牌阶段第X张牌被使用后，若你为使用者或目标，你摸三张牌，并于阶段结束时修改此数字。若不为你的出牌阶段，结束此阶段（X为你选择的数字）。",
  ["@[private]emo__dunshi"] = "遁时",
  ["#emo__dunshi-choice"] = "遁时：选择一个数字",

  ["$emo__zhouhuo1"] = "知识，就是力量!",
  ["$emo__zhouhuo2"] = "魔法，为我而存在。",
  ["$emo__zhuoshao1"] = "替你点个蜡。",
  ["$emo__zhuoshao2"] = "哟呵~火烧屁屁罗!",
  ["$emo__dunshi1"] = "你的番外篇，到此完结！",
  ["$emo__dunshi2"] = "这次换我来找到大家~",
  ["~moe__angela"] = "玩火…自焚……",
}



moe__yangjian:addSkill(emo__shenbian)

local emo__shenchong = fk.CreateTriggerSkill{
  name = "emo__shenchong",
  anim_type = "drawcard",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.RoundStart, fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.RoundStart then
        return player.room:getTag("RoundCount") == 1
      else
        return table.find(player:getTableMark(self.name), function (id)
          local place = player.room:getCardArea(id)
          return (place == Card.DiscardPile or place == Card.DrawPile or place == Card.PlayerHand)
          and player.room:getCardOwner(id) ~= player
        end)
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name, 1)
    room:notifySkillInvoked(player, self.name, "drawcard")
    if event == fk.RoundStart then
      local get = {room:printCard("wardog", Card.Club, 2).id, room:printCard("eagle", Card.Diamond, 2).id}
      for _, id in ipairs(get) do
        room:setCardMark(Fk:getCardById(id), "@@emo__shenchong", 1)
      end
      room:setPlayerMark(player, self.name, get)
      room:obtainCard(player, get, true, fk.ReasonJustMove, player.id, self.name)
    else
      local get = table.filter(player:getTableMark(self.name), function(id)
        local place = player.room:getCardArea(id)
        return (place == Card.DiscardPile or place == Card.DrawPile or place == Card.PlayerHand)
        and player.room:getCardOwner(id) ~= player
      end)
      room:obtainCard(player, get, true, fk.ReasonPrey, player.id, self.name)
    end
  end,

  -- 特殊语音啦
  refresh_events = {fk.CardUsing},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasShownSkill(self) and (data.card.name == "wardog" or data.card.name == "eagle")
  end,
  on_refresh = function (self, event, target, player, data)
    player:broadcastSkillInvoke(self.name, data.card.name == "wardog" and 2 or 3)
  end,
}






local moe__whisperain = General:new(extension, "moe__whisperain", "moe", 1, 1, General.Female)

local emo__fusheng = fk.CreateTriggerSkill{
  name = "emo__fusheng",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.HpChanged, fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if event == fk.HpChanged then
      return target == player and player:hasSkill(self) and player.hp == 0 and not player:isNude()
    else
      return player.rest > 0 and player.tag[self.name]
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.HpChanged then
      local card = table.random(player:getCardIds("he"))
      if not card then return end
      room:throwCard(card, self.name, player, player)
      player.tag[self.name] = true
      room:setPlayerRest(player, 1)
      if not player.dead then
        player.dead = true
        table.removeOne(room.alive_players, player)
        room:broadcastProperty(player, "dead")
      end
    else
      player.tag[self.name] = nil
      room:setPlayerRest(player, 0)
      if player.dead then
        room:revivePlayer(player, false, "rest")
      end
      local x = 1 - player.hp
      if x ~= 0 then
        room:changeHp(player, x, nil, self.name)
      end
    end
  end,
}
moe__whisperain:addSkill(emo__fusheng)

local emo__liaodan = fk.CreateActiveSkill{
  name = "emo__liaodan",
  anim_type = "support",
  card_num = 1,
  target_num = 1,
  prompt = "#emo__liaodan",
  card_filter = function (self, to_select, selected)
    return #selected == 0 and table.contains(Self.player_cards[Player.Hand], to_select) 
  end,
  target_filter = function(self, to_select, selected, cards)
    return #selected == 0 and to_select ~= Self.id and #cards == 1
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 20
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    room:obtainCard(to, effect.cards, false, fk.ReasonGive, player.id, self.name)
    if not to.dead then
      room:damage { from = player, to = to, damage = 1, skillName = self.name }
    end
    if player.dead or to.dead then return end
    local suits = {}
    for _, id in ipairs(to:getCardIds("h")) do
      table.insertIfNeed(suits, Fk:getCardById(id).suit)
    end
    table.removeOne(suits, Card.NoSuit)
    if #suits == 0 then return end
    if room:askForChoice(player, {"#emo__liaodan_recover::"..to.id..":"..#suits, "#emo__liaodan_draw::"..to.id..":"..#suits}, self.name):startsWith("#emo__liaodan_recover") then
      room:recover { num = #suits, skillName = self.name, who = to, recoverBy = player }
    else
      to:drawCards(#suits, self.name)
    end
  end,
}
moe__whisperain:addSkill(emo__liaodan)


Fk:loadTranslationTable{
  ["moe__whisperain"] = "絮雨",
  ["#moe__whisperain"] = "不死游医",
  
  ["emo__fusheng"] = "浮生",
  [":emo__fusheng"] = "锁定技，每当你体力值变化后，若你有牌且当前体力值为0，则随机弃置一张牌并进入修整状态，且本回合结束时，你解除休整状态并调整体力值至1点。",

  ["emo__liaodan"] = "疗弹",
  [":emo__liaodan"] = "出牌阶段限20次，你可以交给一名其他角色一张手牌，对其造成1点伤害，然后你选一项：1.令其回复X点体力；2.令其摸X张牌（X为其手牌中的花色数）。",
  ["#emo__liaodan"] = "疗弹：交给其他角色一张手牌并对其造成1点伤害，然后令其摸牌或回复体力",
  ["#emo__liaodan_recover"] = "令 %dest 回复 %arg 点体力",
  ["#emo__liaodan_draw"] = "令 %dest 摸 %arg 张牌",
}

local moe__valeera = General:new(extension, "moe__valeera", "moe", 3, 3, General.Female)

local emo__qianxing = fk.CreateTriggerSkill{
  name = "emo__qianxing",
  frequency = Skill.Compulsory,
  events = {"fk.GeneralAppeared"},
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local skills = table.filter({"emo__qiji", "emo__piaoqie", "emo__luanwu", "emo__baopai", "emo__shijun"}, function (s)
      return not player:hasSkill(s, true)
    end)
    if #skills == 0 then return end
    room:handleAddLoseSkills(player, table.concat(table.random(skills, 2), "|"))
  end,
}
emo__qianxing.isHiddenSkill = true
moe__valeera:addSkill(emo__qianxing)

local emo__xiaoshi = fk.CreateTriggerSkill{
  name = "emo__xiaoshi",
  frequency = Skill.Limited,
  events = {fk.EnterDying},
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
    and #player.room.general_pile > 0
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local choice = "mainGeneral"
    if player.deputyGeneral ~= "" then
      room:askForChoice(player, {"mainGeneral", "deputyGeneral"}, self.name, "#emo__xiaoshi-choice")
    end
    local num = math.max(3, math.min(18, room.settings.generalNum))
    local general = room:askForGeneral(player, table.random(room.general_pile, num), 1)
    room:changeHero(player, general, false, choice == "deputyGeneral", true, false, true)
    general = Fk.generals[general]
    if player.dead then return end
    local x = general.maxHp - player.maxHp
    if x > 0 then
      room:changeMaxHp(player, x)
      if player.dead then return end
    end
    x = general.hp - player.hp
    if x > 0 then
      room:recover { num = x, skillName = self.name, who = player, recoverBy = player }
      if player.dead then return end
    end
    x = general.shield - player.shield
    if x > 0 then
      room:changeShield(player, x)
    end
  end,
}
moe__valeera:addSkill(emo__xiaoshi)

local emo__qiji = fk.CreateTriggerSkill{
  name = "emo__qiji",
  events = {"fk.GeneralAppeared", fk.CardUsing},
  can_trigger = function (self, event, target, player, data)
    if event == "fk.GeneralAppeared" then
      return target == player and player:hasSkill(self)
    else
      return target == player and player:hasSkill(self) and data.card.type == Card.TypeTrick
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == "fk.GeneralAppeared" then
      for i = 1, 10 do
        local id = room:printCard("cent_coin", math.random(4), 1).id
        table.insert(room.draw_pile, math.random(1, #room.draw_pile), id)
        room:setCardArea(id, Card.DrawPile, nil)
      end
      room:syncDrawPile()
      room:doBroadcastNotify("UpdateDrawPile", tostring(#room.draw_pile))
    else
      player:drawCards(1, self.name)
      if not player.dead then
        room:setPlayerMark(player, "@@emo__qiji", true)
      end
    end
  end,

  refresh_events = {fk.CardUsing},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@@emo__qiji") ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@@emo__qiji", 0)
  end,
}

local emo__qiji_targetmod = fk.CreateTargetModSkill{
  name = "#emo__qiji_targetmod",
  bypass_times = function(self, player, skill, scope, card)
    return card and player:getMark("@@emo__qiji") ~= 0
  end,
}
emo__qiji:addRelatedSkill(emo__qiji_targetmod)

moe__valeera:addRelatedSkill(emo__qiji)


local emo__piaoqie = fk.CreateTriggerSkill{
  name = "emo__piaoqie",
  events = {"fk.GeneralAppeared"},
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local kingdoms = {}
    for _, p in ipairs(room.alive_players) do
      table.insertIfNeed(kingdoms, p.kingdom)
    end
    table.removeOne(kingdoms, player.kingdom)
    local skillmap = {}
    for _, kd in ipairs(kingdoms) do
      skillmap[kd] = {}
    end
    for _, gname in ipairs(room.general_pile) do
      local g = Fk.generals[gname]
      if skillmap[g.kingdom] ~= nil then
        for _, s in ipairs(g:getSkillNameList(false)) do
          if not player:hasSkill(s, true) then
            table.insertIfNeed(skillmap[g.kingdom], s)
          end
        end
      end
    end
    local skills = U.getRandomCards(skillmap, #kingdoms)
    if #skills > 0 then
      room:handleAddLoseSkills(player, table.concat(skills, "|"))
    end
  end,
}
moe__valeera:addRelatedSkill(emo__piaoqie)

local emo__luanwu = fk.CreateTriggerSkill{
  name = "emo__luanwu",
  mute = true,
  events = {"fk.GeneralAppeared", fk.EventPhaseStart},
  can_trigger = function (self, event, target, player, data)
    if target == player and player:hasSkill(self) and not player:isKongcheng() then
      return event == "fk.GeneralAppeared" or player.phase == Player.Play
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    for i = 1, 4 do
      if player.dead or player:isKongcheng() then break end
      local success, dat = room:askForUseViewAsSkill(player, "emo__luanwu_viewas", "#emo__luanwu-use:::"..i, true,
      {bypass_times = true})
      if not success or not dat then break end
      player:broadcastSkillInvoke(self.name)
      if i == 1 then
        room:notifySkillInvoked(player, self.name, "offensive")
      end
      local card = Fk:cloneCard("slash")
      card:addSubcard(dat.cards[1])
      card.skillName = self.name
      local use = {
        from = player.id,
        tos = table.map(dat.targets, function(p) return {p} end),
        card = card,
        extraUse = true,
      }
      room:useCard(use)
    end
  end,
}
moe__valeera:addRelatedSkill(emo__luanwu)

local emo__luanwu_viewas = fk.CreateViewAsSkill{
  name = "emo__luanwu_viewas",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and table.contains(Self:getCardIds("h"), to_select)
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return nil end
    local c = Fk:cloneCard("slash")
    c.skillName = "emo__luanwu"
    c:addSubcard(cards[1])
    return c
  end,
}
Fk:addSkill(emo__luanwu_viewas)

local emo__baopai = fk.CreateTriggerSkill{
  name = "emo__baopai",
  anim_type = "drawcard",
  events = {"fk.GeneralAppeared", fk.TargetConfirmed, fk.TargetSpecified},
  can_trigger = function (self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == "fk.GeneralAppeared" then
        return player.room:getBanner("@[:]emo__baopai") == nil
      else
        return data.card.trueName == "slash"
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    if event == "fk.GeneralAppeared" then
      self.cost_data = nil
      return true
    else
      local to = (event == fk.TargetSpecified and data.to or data.from)
      if room:getPlayerById(to).dead then return false end
      self.cost_data = {tos = {to}}
      return room:askForSkillInvoke(player, self.name, nil, "#emo__baopai-invoke:"..to)
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == "fk.GeneralAppeared" then
      room:setBanner("@[:]emo__baopai", "emo__pilao")
      room.logic:addTriggerSkill(Fk.skills["emo__pilao"])
      room.logic:trigger("fk.EmoPilaoCheck", nil, Util.DummyTable, false)
    else
      local to = room:getPlayerById(self.cost_data.tos[1])
      player:drawCards(2, self.name)
      if not to.dead then
        to:drawCards(2, self.name)
      end
    end
  end,
}
moe__valeera:addRelatedSkill(emo__baopai)

local emo__pilao = fk.CreateTriggerSkill{
  name = "emo__pilao",
  anim_type = "negative",
  events = {fk.AfterCardsMove, fk.TurnStart, "fk.EmoPilaoCheck"},
  can_trigger = function(self, event, target, player, data)
    if player.dead then return end
    if event == fk.TurnStart then
      return target == player and player:getMark("@!exhausted") > 0
    elseif event == "fk.EmoPilaoCheck" then
      return player:getHandcardNum() > 10
    elseif player:getHandcardNum() > 10 then
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Card.PlayerHand then
          return true
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      room:damage { to = target, damage = player:getMark("@!exhausted"), skillName = self.name }
    elseif player:getHandcardNum() > 10 then
      room:addPlayerMark(player, "@!exhausted", 1)
      local cards = {}
      local hands = player.player_cards[Card.PlayerHand]
      for i = #hands, 1, -1 do
        if i <= 10 then break end
        table.insert(cards, hands[i])
      end
      room:moveCardTo(cards, Card.Void, nil, fk.ReasonJustMove, self.name, nil, true)
    end
  end,
}
moe__valeera:addRelatedSkill(emo__pilao)

local emo__shijun = fk.CreateTriggerSkill{
  name = "emo__shijun",
  anim_type = "drawcard",
  events = {fk.TurnStart, "fk.GeneralAppeared"},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local get
    if not table.find(player:getCardIds("he"), function (id)
      return Fk:getCardById(id).name == "kingsbane"
    end) then
      get = table.find(table.connect(room.draw_pile, room.void), function (id)
        return Fk:getCardById(id).name == "kingsbane"
      end)
      if not get then
        get = room:getTag(self.name)
        if get == nil then
          get = room:printCard("kingsbane", Card.Spade, 1).id
          room:setTag(self.name, get)
        elseif room:getCardArea(get) ~= Card.DrawPile and room:getCardArea(get) ~= Card.Void then
          get = nil
        end
      end
    end
    if not get then
      get = room:getCardsFromPileByRule("slash", 1, "allPiles")[1]
    end
    if get then
      room:moveCardTo(get, Player.Hand, player, fk.ReasonJustMove, self.name, nil, true)
      if table.contains(player.player_cards[Card.PlayerHand], get) then
        Fk:filterCard(get, player)
        get = Fk:getCardById(get)
        if get.name == "kingsbane" and player:canUseTo(get, player) then
          room:useCard{from = player.id, tos = {{player.id}}, card = get}
        end
      end 
    end
  end,
}
moe__valeera:addRelatedSkill(emo__shijun)


Fk:loadTranslationTable{
  ["moe__valeera"] = "瓦莉拉",
  
  ["emo__qianxing"] = "潜行",
  [":emo__qianxing"] = "隐匿。锁定技，当你登场时，你随机获得两个“潜行者”流派技能。",

  ["emo__xiaoshi"] = "消失",
  [":emo__xiaoshi"] = "限定技，当你进入濒死状态时，你可以移去并重新选择一张武将牌，然后将体力上限、体力值、护甲值增加至此武将的初始值。",
  ["#emo__xiaoshi-choice"] = "消失：选择你要更换的武将牌",

  ["emo__qiji"] = "奇迹",
  [":emo__qiji"] = "当你登场时，将十张【幸运币】洗入牌堆。每当你使用锦囊牌时，摸一张牌，并令你下一张牌无次数限制。",
  ["@@emo__qiji"] = "奇迹",

  ["emo__piaoqie"] = "剽窃",
  [":emo__piaoqie"] = "当你登场时，你从武将池随机获得场上每个其他势力各一个技能。",

  ["emo__luanwu"] = "乱舞",
  [":emo__luanwu"] = "当你登场时，或出牌阶段开始时，你可以将至多四张手牌依次当【杀】使用。",
  ["emo__luanwu_viewas"] = "乱舞",
  ["#emo__luanwu-use"] = "乱舞：你可以将一张手牌当【杀】使用(第 %arg 张，至多 4 张)",

  ["emo__baopai"] = "爆牌",
  [":emo__baopai"] = "当你登场时，为本局添加法则技〖疲劳〗。每当你使用【杀】指定目标或成为【杀】目标后，你可以与对方各摸两张牌。",
  ["#emo__baopai-invoke"] = "爆牌：你可以与 %src 各摸两张牌",

  ["emo__pilao"] = "疲劳",
  [":emo__pilao"] = "当任何玩家手牌大于10张时，其将超出部分的最右侧手牌移出游戏，并获得1枚“疲劳”标记。有此标记的角色于回合开始时受到X点无来源伤害（X为其“疲劳”标记数）。",
  ["@[:]emo__baopai"] = "法则技",
  ["@!exhausted"] = "疲劳",

  ["emo__shijun"] = "弑君",
  [":emo__shijun"] = "当你登场时，或回合开始时，你从游戏外或牌堆获得一张【弑君】并使用之，若无法获得，改为获得一张【杀】。",

  ["$emo__baopai1"] = "花儿虽美，刺也伤人。",
  ["$emo__luanwu1"] = "谁愿与我起舞？",
  ["$emo__luanwu2"] = "独舞，不如对舞。",
  ["$emo__xiaoshi1"] = "",
  ["$emo__xiaoshi2"] = "",
}




-- zhizi tomoko
local moe__sophon = General:new(extension, "moe__sophon", "moe", 4, 4, General.Female)

local emo__zhizao = fk.CreateTriggerSkill{
  name = "emo__zhizao",
  anim_type = "drawcard",
  derived_piles = "emo__proton",
  events = {fk.GameStart, fk.EventPhaseStart},
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.GameStart then return true end
      return target == player and player.phase == Player.Play
      and table.find(player.room.alive_players, function (p)
        return p ~= player and not p:isKongcheng()
      end)
    end
  end,
  on_cost = function (self, event, target, player, data)
    if event == fk.GameStart then
      self.cost_data = nil
      return true
    end
    local targets = table.filter(player.room:getOtherPlayers(player), function (p) return not p:isKongcheng() end)
    local tos = player.room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, 1,
    "#emo__zhizao-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart then
      local cardsMap = {}
      for _, id in ipairs(Fk:getAllCardIds()) do
        local c = Fk:getCardById(id)
        if not c.is_derived then
          cardsMap[c.name] = cardsMap[c.name] or {}
          table.insert(cardsMap[c.name], id)
        end
      end
      local cards = {}
      for _, cds in pairs(cardsMap) do
        local c = Fk:getCardById(table.random(cds))
        table.insert(cards, room:printCard(c.name, c.suit, c.number))
      end
      if #cards > 0 then
        player:addToPile("emo__proton", cards, false, self.name)
      end
    else
      local to = room:getPlayerById(self.cost_data.tos[1])
      local cards = to:getCardIds("h")
      --U.viewCards(player, cards, self.name, "$ViewCardsFrom:"..to.id)
      local names = {}
      for _, id in ipairs(cards) do
        table.insertIfNeed(names, Fk:getCardById(id).name)
      end
      local get = {}
      for _, id in ipairs(player:getPile("emo__proton")) do
        if table.contains(names, Fk:getCardById(id).name) then
          table.insert(get, id)
        end
      end
      if #get > 0 then
        room:obtainCard(player, get, false, fk.ReasonJustMove, player.id, self.name)
      else
        player:addToPile("emo__proton", cards, false, self.name)
        room:setPlayerMark(player, "emo__zhankai_avail", 1)
      end
    end
  end,
}
moe__sophon:addSkill(emo__zhizao)

local emo__zhankai = fk.CreateActiveSkill{
  name = "emo__zhankai",
  anim_type = "offensive",
  card_num = 0,
  target_num = 0,
  card_filter = Util.FalseFunc,
  frequency = Skill.Limited,
  prompt = "#emo__zhankai",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and player:getMark("emo__zhankai_avail") ~= 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:throwAllCards("hej")
    room:obtainCard(player, player:getPile("emo__proton"), true, fk.ReasonJustMove, player.id, self.name)
  end,
}
moe__sophon:addSkill(emo__zhankai)

local emo__suosi = fk.CreateTriggerSkill{
  name = "emo__suosi",
  anim_type = "control",
  events = {fk.TurnStart, fk.CardUsing},
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.TurnStart then
        return #player:getPile("emo__proton") > 0 and target == player
      else
        return table.contains(target:getTableMark("@@emo__suosi"), player.id)
        and table.find(player:getPile("emo__proton"), function (id)
          return Fk:getCardById(id).name == data.card.name
        end)
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    if event == fk.TurnStart then
      local tos = player.room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, 1,
      "#emo__suosi-choose", self.name, true)
      if #tos > 0 then
        self.cost_data = {tos = tos}
        return true
      end
    else
      self.cost_data = {tos = {target.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      local to = room:getPlayerById(self.cost_data.tos[1])
      if not table.contains(to:getTableMark("@@emo__suosi"), player.id) then
        room:addTableMark(to, "@@emo__suosi", player.id)
      end
    else
      if data.toCard then
        if math.random() < 0.5 then
          data.toCard = nil
        end
      elseif data.tos then
        local tos = {}
        local curTar = TargetGroup:getRealTargets(data.tos)
        local avail = table.map(table.filter(room.alive_players, function (p)
          return not target:isProhibited(p, data.card) and (data.card.skill:modTargetFilter(p.id, {}, target, data.card, false)
          or data.card.trueName == "slash")
        end), Util.IdMapper)
        if #avail == 0 then return end
        if data.card.skill:getMinTargetNum() > 1 then
          if #data.tos > 0 then
            tos = table.random(avail, 1)
            data.tos[1][1] = tos[1]
          end
        else
          if data.card.multiple_targets and #curTar > 1 then
            tos = table.random(avail, math.random(1, #avail))
          else
            tos = table.random(avail, #curTar)
          end
          data.tos = table.map(tos, function (id) return {id} end)
        end
        room:sendLog{type = "#ChangeTarget", from = target.id, arg = data.card:toLogString(), to = tos}
      end
    end
  end,

  refresh_events = {fk.EventLoseSkill, fk.BuryVictim, fk.TurnStart},
  can_refresh = function(self, event, target, player, data)
    if target and table.contains(player:getTableMark("@@emo__suosi"), target.id) then
      if event == fk.EventLoseSkill then
        return data == self
      else
        return target:hasSkill(self, true, true)
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:removeTableMark(player, "@@emo__suosi", target.id)
  end,
}
moe__sophon:addSkill(emo__suosi)


Fk:loadTranslationTable{
  ["moe__sophon"] = "智子",
  
  ["emo__zhizao"] = "智造",
  [":emo__zhizao"] = "游戏开始时，你将开启的每一种牌复制到你武将牌上称为“质”。出牌阶段开始时，你可以观看一名其他角色的手牌，若“质”中有其手牌中含有的牌名，你获得这些“质”，否则将其所有手牌置入“质”中。",
  ["emo__proton"] = "质",
  ["#emo__zhizao-choose"] = "智造：观看一名其他角色的手牌，获得其中含有牌名的“质”",

  ["emo__zhankai"] = "展开",
  [":emo__zhankai"] = "限定技，出牌阶段，若你曾将任何角色手牌置入“质”中，你可以弃置区域内所有牌，获得所有“质”。",
  ["#emo__zhankai"] = "展开：你可以弃置所有牌，获得所有“质”！",

  ["emo__suosi"] = "锁死",
  [":emo__suosi"] = "回合开始时，若你有“质”，你可以选择一名角色，直到你下回合开始，其使用一张“质”中拥有的牌时，改为随机目标（若原目标为牌，改为50%概率失效）。",
  ["#emo__suosi-choose"] = "锁死：你可以令一名角色使用牌时改为随机目标！",
  ["@@emo__suosi"] = "锁死",
  ["#ChangeTarget"] = "%from 使用的 %arg 目标被改为 %to",

  ["$emo__zhankai1"] = "",
  ["$emo__zhankai2"] = "",
}




return extension

